//package com.eastfair.handler;
//
//import cn.hutool.core.date.LocalDateTimeUtil;
//import com.eastfair.cache.gateway.LoginCacheKeyBuilder;
//import com.eastfair.cache.repository.CacheOps;
//import com.eastfair.constant.BusinessConstant;
//import com.eastfair.core.model.CacheKey;
//import com.eastfair.log.point.PointUtil;
//import com.eastfair.point.business.auth.BusinUpdUserPoint;
//import com.eastfair.point.business.gateway.BusinBalckPoint;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import java.text.SimpleDateFormat;
//import java.time.ZoneOffset;
//import java.util.Arrays;
//import java.util.Date;
//
///**
// * 登陆事件
// * ligang
// */
//@Component
//public class LoginHandler {
//    @Autowired
//    private CacheOps cacheOps;
//    @Autowired
//    PointUtil pointUtil;
//
//    @Value("${com.eastfair.firstLoginFailNum}")
//    private Integer firstLoginFailNum;
//
//    @Value("${com.eastfair.secondLoginFailNum}")
//    private Integer secondLoginFailNum;
//
//    /**
//     * 登陆成功操作
//     */
//    public void executeLoginSucc(Long userId) {
//        //删除当天登陆失败次数
//        CacheKey key = new LoginCacheKeyBuilder().key(queryUserKey(userId));
//        cacheOps.del(key);
//    }
//
//    /**
//     * 登陆失败操作
//     */
//    public void executeLoginFail(Long userId) {
//        //添加当天登陆失败次数
//        CacheKey key = new LoginCacheKeyBuilder().key(queryUserKey(userId));
//        Long i = cacheOps.incr(key);
//        if (firstLoginFailNum == i.intValue()) {
//            //登陆3次,禁止登陆10分钟
//            BusinBalckPoint businBalckPoint = new BusinBalckPoint();
//            businBalckPoint.setUserId(userId);
//            businBalckPoint.setStartTime(LocalDateTimeUtil.now());
//            businBalckPoint.setEndTime(LocalDateTimeUtil.now().plusMinutes(10));
//            pointUtil.addBusinPointMsg(businBalckPoint);
//        } else if (secondLoginFailNum == i.intValue()) {
//            //登陆5次，账号锁定
//            BusinUpdUserPoint businUpdUserPoint2 = new BusinUpdUserPoint();
//            businUpdUserPoint2.setUserId(userId);
//            businUpdUserPoint2.setIsEnabled(BusinessConstant.NO);
//            pointUtil.addBusinPointMsg(businUpdUserPoint2);
//        }
//    }
//
//    private String queryUserKey(Long userId) {
//        return new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + userId;
//    }
//}
